<template>
    <div flex h-full>
        <div m-auto bg-gray-100 w-350 flex flex-col items-center border border-gray-300 p-30 rounded-10>
            <h5 text-24 font-normal color="#6a6a6a">
                {{ title }}
            </h5>
            <div mt-30 w-full>
            </div>

            <div mt-20 w-full text-center>
                <icon-simple-icons:gitee @click="handleLogin" text-24 v-if="appStore.config.giteeLoginEnabled" />
            </div>
        </div>
    </div>
</template>
  
<script setup>
import { useAccountStore } from '@/stores/account';
import { useAppStore } from '@/stores/app';
import { toHome } from '@/router'
import { getSiteConfig } from '@/apis/config';
import { getToken } from '@/utils';

const title = import.meta.env.VITE_APP_TITLE;
const accountStore = useAccountStore();
const appStore = useAppStore();

async function handleLogin() {
    const url = import.meta.env.VITE_API_BASE_PATH;
    window.open(url + "/oauth/render/gitee", "Gitee", "resizable=no")
}

async function loadAccountInfo() {
    const config = await getSiteConfig();

    if (config.code === 0)
        appStore.config = config.content;

    const token = getToken();

    if (token)
        await accountStore.getAccountInfo();

    if (accountStore.info.id)
        toHome();
}

loadAccountInfo();
</script>